package com.send.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import com.alibaba.dubbo.config.annotation.Service;
import com.send.api.IMailService;
import com.send.config.EmailConfig;
import com.send.util.MailUtil;

@Service
public class MailServiceImpl implements IMailService {
	private static final Logger logger = LoggerFactory.getLogger(MailServiceImpl.class);

	@Autowired
	JavaMailSender javaMailSender;

	@Value("${spring.mail.username}")
	public String USER_NAME;//发送者

	static {
		 System.setProperty("mail.mime.splitlongparameters","false");
	}


	@Override
	public void send(EmailConfig mail) throws Exception {

	}

	@Override
	public void sendHtml(EmailConfig mail) throws Exception {
		try {
			MailUtil mailUtil = new MailUtil();
			SimpleMailMessage message = new SimpleMailMessage();
			message.setTo(mail.getToAddress());
			message.setSubject(mail.getSubject());
			message.setText(mail.getContent());
			mailUtil.start(javaMailSender, message);
			/*javaMailSender.send(testMessage);*/
		} catch (Exception mex) {
			throw new RuntimeException("Error Sending mail", mex);
		}
	}
}
